package com.zzyl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingProjectController
 * @Author luohai
 * @Date 2024-10-15
 */
@RestController
@RequestMapping("/nursing_project")
@Slf4j
@Api(tags = "护理项目相关接口")
public class NursingProjectController extends BaseController{
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 护理项目分页查询
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping
    @ApiOperation(value = "护理项目分页查询")
    @ApiOperationSupport(includeParameters = {"name","pageNum","pageSize","status"})
    public ResponseResult<PageResponse<NursingProjectVo>> nursingPaginationQuery(
            @ApiParam(value = "护理项目名称") String name,
            @ApiParam(value = "当前页数",defaultValue = "1") Integer pageNum,
            @ApiParam(value = "当页显示数",defaultValue = "5") Integer pageSize,
            @ApiParam(value = "状态") Integer status
    ){
        PageResponse<NursingProjectVo> pageResponse=nursingProjectService.nursingPaginationQuery(name,pageNum,pageSize,status);
        return success(pageResponse);
    }

    /**
     * 新增护理项目
     * @param nursingProjectDto
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理项目")
    @ApiOperationSupport(includeParameters = {"nursingProjectDto.image","nursingProjectDto.name",
            "nursingProjectDto.nursingRequirement","nursingProjectDto.orderNo","nursingProjectDto.price",
            "nursingProjectDto.remark","nursingProjectDto.status","nursingProjectDto.unit"})
    public ResponseResult addNursingProject(@ApiParam(value = "NursingProjectDto对象",required = true) @RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.addNursingProject(nursingProjectDto);
        return success();
    }

    /**
     * 根据id查询护理项目（数据回显）
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> searchNursingProjectById(
            @ApiParam(value = "护理id",required = true) @PathVariable Long id){
       NursingProjectVo nursingProjectVo=nursingProjectService.searchNursingProjectById(id);
       return success(nursingProjectVo);
    }

    /**
     * 修改护理项目
     * @param nursingProjectDto
     * @return
     */
    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult modifyNursingProject(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.modifyNursingProject(nursingProjectDto);
        return success();
    }

    /**
     * 护理项目启禁用
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("护理项目启禁用")
    public ResponseResult startAndBan(
            @ApiParam(value = "id") @PathVariable Long id,
            @ApiParam(value = "状态") @PathVariable Integer status){
        nursingProjectService.startAndBan(id,status);
        return success();
    }

    /**
     * 根据id删除护理项目
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理项目")
    public ResponseResult deleteNursingProject(@ApiParam(value = "id",required = true) @PathVariable Long id){
        nursingProjectService.deleteNursingProject(id);
        return success();
    }

    /**
     * 查询所有护理项目
     * @return
     */
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> searchAll(){
        List<NursingProjectVo> list=nursingProjectService.searchAll();
        return success(list);
    }
}
